package net.wicp.tams.commons.binlog.replication.down;

import java.io.IOException;

import org.apache.tapestry5.json.JSONObject;

import net.wicp.tams.commons.apiext.ByteUtil.AssitRead;
import net.wicp.tams.commons.binlog.bean.PacketBean;
import net.wicp.tams.commons.binlog.replication.AbsPacketRead;
import net.wicp.tams.commons.io.UnsignedLong;

/**
 * sql查询时的头
 * 
 * @author andy.zhou
 *
 */
public class RsHeaderPacket extends AbsPacketRead {
	private static final long serialVersionUID = 1L;
	private UnsignedLong fieldCount;
	private UnsignedLong extra;

	public RsHeaderPacket(PacketBean packetBean) {
		super(packetBean);
	}

	@Override
	public JSONObject getBody() {
		JSONObject retobj = new JSONObject("fieldCount", fieldCount.intValue(), "extra", extra.intValue());
		return retobj;
	}

	@Override
	protected void readBody(AssitRead reader) throws IOException {
		fieldCount = reader.readUnsignedLong();
		if (reader.hasMore())
			extra = reader.readUnsignedLong();
	}

	public UnsignedLong getFieldCount() {
		return fieldCount;
	}

	public UnsignedLong getExtra() {
		return extra;
	}

}
